<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/2/22
 * Time: 22:41
 */
namespace Home\Model;
use Think\Model;
class IndexModel extends Model
{
    public function response($postObj)
    {
        if (strtolower($postObj->MsgType) == 'event') {
            //如果是关注subscribe
            if (strtolower($postObj->Event) == 'subscribe') {
                //回复用户消息
                $toUser = $postObj->FormUserName;
                $fromUser = $postObj->ToUserName;
                $time = time();
                $msgType = 'text';
                $content = '欢迎关注tb的公众号！';
                $template = "
                            <xml>
                                <ToUserName><![CDATA[%s]]></ToUserName>
                                <FromUserName><![CDATA[%s]]></FromUserName>
                                <CreateTime>%s</CreateTime>
                                <MsgType><![CDATA[%s]]></MsgType>
                                <Content><![CDATA[%s]]></Content>
                            </xml>";
                $info = sprintf($template, $toUser, $fromUser, $time, $msgType, $content);
                echo $info;

            }
        }

    }
}